﻿#region License Info

//Component of Cronos Package, http://www.codeplex.com/cronos
//Copyright (C) 2009 Anthony Brockwell

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#endregion


using System;
using System.Windows.Forms;

namespace CronosII
{
    public partial class OrderSelectForm : Form
    {
        public int AROrder { get; set; }
        public int MAOrder { get; set; }
        public int ThirdOrder { get; set; }

        /// <summary>
        /// this version asks for only one order
        /// </summary>
        /// <param name="order"></param>
        /// <param name="orderLabel"></param>
        public OrderSelectForm(int order, string orderLabel)
        {
            InitializeComponent();
            label1.Text = orderLabel;
            label2.Hide();
            label3.Hide();
            AROrder = order;
            arOrderUpDown.Value = AROrder;
            maOrderUpDown.Hide();
            thirdUpDown.Hide();
        }

        /// <summary>
        /// this version asks for two orders
        /// </summary>
        /// <param name="arOrder"></param>
        /// <param name="maOrder"></param>
        /// <param name="order1Label"></param>
        /// <param name="order2Label"></param>
        public OrderSelectForm(int arOrder, int maOrder, string order1Label, string order2Label)
        {
            InitializeComponent();
            label1.Text = order1Label;
            label2.Text = order2Label;
            label3.Hide();
            AROrder = arOrder;
            MAOrder = maOrder;
            maOrderUpDown.Value = MAOrder;
            arOrderUpDown.Value = AROrder;
            thirdUpDown.Hide();
        }

        /// <summary>
        /// this version asks for three orders
        /// </summary>
        public OrderSelectForm(int o1, int o2, int o3, string l1, string l2, string l3)
        {
            InitializeComponent();
            label1.Text = l1;
            label2.Text = l2;
            label3.Text = l3;
            AROrder = o1;
            MAOrder = o2;
            ThirdOrder = o3;
            maOrderUpDown.Value = MAOrder;
            arOrderUpDown.Value = AROrder;
            thirdUpDown.Value = ThirdOrder;
        }

        private bool CheckStuff()
        {
            bool isOK = true;
            AROrder = (int) Math.Round(arOrderUpDown.Value);
            isOK &= AROrder >= 0;
            MAOrder = (int) Math.Round(maOrderUpDown.Value);
            isOK &= MAOrder >= 0;
            ThirdOrder = (int) Math.Round(thirdUpDown.Value);
            isOK &= ThirdOrder >= 0;
            if (!isOK)
                MessageBox.Show("Invalid integer in one or more fields.", "Error");
            return isOK;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if(CheckStuff())
              Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
             Close();
        }
    }
}
